AddCSLuaFile('shared.lua');
AddCSLuaFile('cl_init.lua');

include('shared.lua');

function ENT:Initialize()
	//Setup explosive timer
	self.Entity:SetNetworkedInt("bombtime", 0);
	
	self.Entity:SetModel("models/weapons/w_slam.mdl");
	self.Entity:PhysicsInit( SOLID_VPHYSICS );
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS );
	self.Entity:SetSolid( SOLID_VPHYSICS );
	
	local phys = self.Entity:GetPhysicsObject();
	
	if(phys:IsValid()) then
		phys:Wake();
	end
	
	self.start = CurTime();
end

function ENT:Think()
	local elapsed = CurTime() - self.start;
	local left = 15 - elapsed;
	if(left <= 0) then self:Explode(); end
	self.Entity:SetNetworkedInt("bombtime", math.Round(left));
end

function ENT:Explode()
	local c = constraint.FindConstraint(self.Entity, "Weld");
	c.Entity[1].Entity:TakeDamage(3500, self.Entity:GetOwner());
	local e = EffectData();
	e:SetStart(self.Entity:GetPos());
	e:SetOrigin(self.Entity:GetPos());
	e:SetScale(1);
	util.Effect("Explosion", e);
	self:Remove();
end

function ENT:OnTakeDamage(dmg)
	self:Remove();
end